package com.black.knight.chess.calls;

import org.restlet.resource.ClientResource;

import com.black.knight.chess.common.Activity;
import com.black.knight.chess.common.ActivityEnum;
import com.black.knight.chess.common.ActivityResource;
import com.black.knight.chess.model.SettingsModel;

public class PublishActivityCall implements Runnable {

	private String username;
	
	private ActivityEnum activity;
	
	private String details;
	
	private String name;
	
	public PublishActivityCall(ActivityEnum activity, String username, String name, String details) {
		this.username = username;
		this.details = details;
		this.activity = activity;
		this.name = name;
	}
	
	@Override
	public void run() {
		ClientResource cr = new ClientResource(SettingsModel.SERVICE_URL + "/activities/New");
		
		cr.setRequestEntityBuffering(true);
		
		ActivityResource resource = cr.wrap(ActivityResource.class);
		
		try {
			Activity act = new Activity();
			act.setActivity(activity.toString());
			act.setUsername(username);
			act.setDetails(details);
			act.setName(name);
			
			resource.saveActivity(act);
		} catch (Exception e) {
		}
	}
}
